//
//  UIBarButtonItem+Extension.swift
//  波波微博
//
//  Created by wave on 15/8/6.
//  Copyright © 2015年 wave. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageName:String,target:AnyObject,action:String?) {
        
        let button = UIButton()
        
        //设置属性
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()

        //设置监听方法,判断action是否存在
        if let actionName = action{
            
            button.addTarget(target, action: Selector(actionName), forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        self.init(customView:button)
    }
    
    
    
}